﻿using Mes.Domain.BoundedContext.Entities.WorkOrders;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mes.Infrastructure.Data.BoundedContext.EntityTypeConfigurations.WorkOrders
{
    public class JobHistoryEntityConfig : IEntityTypeConfiguration<JobHistory>
    {
        public void Configure(EntityTypeBuilder<JobHistory> builder)
        {
            builder.ToTable("job_history");
            builder.HasKey(b => new { b.Wo_Id, b.Oper_Id, b.Ent_Id, b.Job_Start_Utc });
            builder.Property(b => b.Ent_Id).HasMaxLength(40).IsRequired();
            builder.Property(b => b.Wo_Id).HasMaxLength(40).IsRequired();
            builder.Property(b => b.Oper_Id).HasMaxLength(40).IsRequired();
            builder.Property(b => b.Job_Start_Utc).IsRequired();
            builder.Property(b => b.Job_Start_Local).IsRequired();
            builder.Property(b => b.Job_Pos).IsRequired();
            builder.Property(b => b.Item_Id).IsRequired();
            builder.Property(b => b.Job_End_Utc);
            builder.Property(b => b.Job_End_Local);
            builder.Property(b => b.Spare1).HasMaxLength(80);
            builder.Property(b => b.Spare2).HasMaxLength(80);
            builder.Property(b => b.Spare3).HasMaxLength(80);
            builder.Property(b => b.Spare4).HasMaxLength(80);
            builder.Property(b => b.Last_Edit_Comment).HasMaxLength(254);
            builder.Property(b => b.Last_Edit_By).HasMaxLength(40);
            builder.Property(b => b.Last_Edit_At).IsRequired();
            builder.Property(b => b.Row_Id).IsRequired().UseIdentityColumn().HasIdentityOptions(startValue: 0, incrementBy: 1, minValue: 0);
        }
    }
}
